package com.cyzy.controller;

import com.cyzy.dao.OrderDto;
import com.cyzy.dto.Result;
import com.cyzy.service.OrderService;
import com.cyzy.vo.ArtGoodVo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cuncun
 * @create 2025-06-18 上午11:19
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //查询用户订单信息（支付与未支付） 参数：用户的类型，用户的id，支付状态
    @GetMapping("/selectOrder")
    public Result selectOrder(@RequestParam("type") String type,@RequestParam("id") Integer id){
        //System.out.println("用户的类型: " + type + "用户的id: " + id + "支付状态 " + payStatus);
        List<OrderDto> orderDto = orderService.selectOrder(type, id);
        return Result.ok().data("orders",orderDto);
    }

    //删除订单
    @GetMapping("/deleteOrder")
    public Result deleteOrder(@RequestParam("orderNo") String orderNo){
        System.out.println("orderNo" + orderNo);
        if(orderNo == null){
            return Result.error().message("参数不能为空！");
        }
        int i = orderService.deleteOrder(orderNo);
        if(i==0){
            return Result.error().message("删除失败");
        }
        return Result.ok().message("删除成功");
    }

    //插入待支付订单
    @PostMapping("/submitOrders")
    public Result submitOrders(@RequestBody ArtGoodVo artGoodVo){
        System.out.println("artGoodVo" + artGoodVo);

        String s = orderService.submitOrders(artGoodVo);

        return Result.ok().message(s);
    }

    //支付订单
    @PostMapping("/payOrder")
    public Result  payOrder(@RequestBody OrderDto OrderDto){
        System.out.println(OrderDto);
        String s = orderService.payOrder(OrderDto);
        return Result.ok().message(s);
    }
}
